using System;
using System.Collections.Generic;
using System.Text;

using ClientGUI.Modules.Drawing;
using System.Xml;

using System.Drawing;

namespace ClientGUI
{
    /// <summary>
    /// Display a numbered list item.
    /// </summary>
    class NumberList:ListSquare
    {
        bool my_amdirty = true;
        int my_numberwidth = 0;
        public NumberList(XmlNode doc, Module parent,
            DisplayDocument host, XmlNode modconfig,
            TagConfig tagconfig)
            : base(doc, parent, host, modconfig, tagconfig)
        {
            
        }


        public override int BulletWidth()
        {
            if (my_amdirty)
            {
                int width = 0;
                for (int i = 1; i <= Children.Count; ++i)
                {
                    Word w = new Word(i.ToString());
                    width = Math.Max(width, (int)w.Width);
                }
                my_numberwidth = width + 1;
                my_amdirty = false;
            }
            return my_numberwidth;
        }

        protected override void Insert(Module child, int at)
        {
            base.Insert(child, at);
            my_amdirty = true;
        }
        protected override void Remove(int at)
        {
            base.Remove(at);
            my_amdirty = true;
        }

        public override void  DrawBullet(Graphics g, Point point, Color color, Module child)
        {
            g.DrawString((Children.IndexOf(child) + 1).ToString() + ".",
                            new Font(FontFamily.GenericSansSerif, 11.0f),
                            new SolidBrush(color), point);
        }
    }
}
